package cn.edu.mju.dilidili.modules.dynamic.controller;


import cn.edu.mju.dilidili.common.utils.AuthUtil;
import cn.edu.mju.dilidili.common.utils.Result;
import cn.edu.mju.dilidili.modules.dynamic.dto.CreateRequestDto;
import cn.edu.mju.dilidili.modules.dynamic.dto.CreateResponseDto;
import cn.edu.mju.dilidili.modules.dynamic.entity.Dynamic;
import cn.edu.mju.dilidili.modules.dynamic.service.DynamicService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qiniu.util.Auth;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 动态信息表 前端控制器
 * </p>
 *
 * @author l
 * @since 2022-09-24
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/action")
public class DynamicController {
    final DynamicService dynamicService;

    @RequestMapping("/getUploadToken")
    Result<String> getUploadToken() {
        String accessKey = "8N7-BC2MfXtlml8I7JNsTSK00qKAJkbmKD8yVb-S";
        String secretKey = "GqXIZVu7F-4x2k0yas9-Cfe3c65fQ5O5vzWMFNzH";
        String bucket = "dilidili-l";
        Auth auth = Auth.create(accessKey, secretKey);
        String upToken = auth.uploadToken(bucket);
        return new Result<>(upToken);
    }

    @RequestMapping("/getPage/{page}")
    Result<Page<Dynamic>> getPage(@PathVariable Integer page) {
        return dynamicService.getPage(page);
    }

    @PostMapping("/create")
    Result<CreateResponseDto> create(@RequestBody CreateRequestDto createRequestDto) {
        return dynamicService.create(createRequestDto);
    }

    @GetMapping("/get/{id}")
    Result<Dynamic> getById(@PathVariable Integer id) {
        return dynamicService.getById(id);
    }
}
